#include <iostream>

#include "iostream"
#include "vector"
#include "unordered_map"
#include "unordered_set"
#include "algorithm"
#include "string"
#include "list"
#include "string.h"

struct TreeNode{
    int left=-1;
    int right=-1;
    int val;
    TreeNode(int val):val(val){}
};

class OneLoop {
public:
    std::vector<TreeNode> nodes;
    std::list<std::vector<int>> draw;
    void add_2_tree(int n){
        nodes.emplace_back(n);
        int new_node=nodes.size()-1;
        int node=0;
        while(node!=-1){
            if(n>nodes[node].val){
                if(nodes[node].right==-1){//找到空位，插入
                    nodes[node].right=new_node;
                    return;
                }
                node=nodes[node].right;
            }
            if(n<nodes[node].val){
                if(nodes[node].left==-1){
                    nodes[node].left=new_node;
                    return;
                }else{
                    node=nodes[node].left;
                }
            }
        }
    }
    void add_line_for_level(std::vector<int> & vec,int level,int num,bool no_child,
        int zz_cnt
    ){
        for(int i=0;i<=level;i++){
            if(i==level){
                vec.push_back(-2);
                vec.push_back(num);
                if(!no_child){
                    vec.push_back(-3);
                }
            }else{
                    vec.push_back(-1);

                vec.push_back(-1);
            }
        }
        if(vec.size()>max_w){
            max_w=vec.size();
        }
    }
    int max_w=0;
    void dfs(int node,int level,
             bool father_is_right,bool is_right,int zz_cnt){
        if(node==-1){
            return;//无效节点
        }
        dfs(nodes[node].right,level+1,is_right, true,
            zz_cnt+father_is_right==is_right?0:1);
//        if(is_right)
        {
            draw.push_back(std::vector<int>());
            add_line_for_level(draw.back(),level,nodes[node].val,
                               nodes[node].left==-1&&nodes[node].right==-1,zz_cnt);
        }
//        else{
//            draw.push_back(std::vector<int>());
//            add_line_for_level(draw.back(),level,nodes[node].val);
//        }
        dfs(nodes[node].left,level+1,is_right, false,
            zz_cnt+father_is_right==is_right?0:1);

    }

    bool run(
//            int n
//            std::string&s1,std::string& s2
    ) {
        char c;
//        draw.push_back("");
//        draw.resize(1);
        while(1){
            int in;std::cin>>in;
            if(nodes.empty()){
                nodes.push_back(TreeNode(in));
            }else{
                add_2_tree(in);
            }

           c=std::cin.get();
            if(c==EOF){
                break;
            }else if(c=='\n'){
                break;
            }
        }
        dfs(0,0, true,true,0);
        for(int i=0;i<max_w;i++){
            //i为扫描的列
            bool begin=false;
            int line_begin=-1;
            int line_end=-1;
            int line_cnt=0;
            for(auto &line:draw){
                if(i<line.size()){
                    if(line_begin==-1){
                        if(line[i]==-2||line[i]==-3){
                            line_begin=line_cnt;
                            line_end=line_cnt;
                        }
                    }else{
                        if(line[i]==-2||line[i]==-3){
                            line_end=line_cnt;
                        }
                    }
                }
                line_cnt++;
            }
            line_cnt=0;
            for(auto &line:draw){
                if(line_cnt>=line_begin&&line_cnt<=line_end){
                    if(i<line.size()&&line[i]==-1){
                        line[i]=-4;
                    }
                }
                line_cnt++;
            }
        }
        for(auto &line:draw){
            for(auto i:line){
                if(i==-1){
                    printf("   ");
                }else{
                    printf("%2d ",i);
                }
            }
            printf("\n");
        }
//        return true;
        if(c==EOF){
            return false;
        }else if(c=='\n'){
            return true;
        }
    }
};

class Solution {
public:
    void run() {

        bool first = true;
        int a, b, c, d, e;
        //        std::cin >> a;
//        std::string s1,s2;
//        while (1){
        while (
//                std::getline(std::cin,s1)
//                std::cin >> a// >> b
                1
                ) {
//            std::getline(std::cin,s2);
            OneLoop l;
            if (!l.run()) {
                return;
            }
        }


    }
};

int main() {

    //    bool cur_num= true;
    Solution().run();
    return 0;
}

